package com.zenithmind.article.pojo.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 作者视图对象
 * 遵循单一职责原则：专注于作者统计信息展示
 * 遵循里氏替换原则：正确继承BaseVO
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@Schema(name = "作者视图对象", description = "作者统计信息展示对象")
public class AuthorVO extends BaseVO {

    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "头像URL")
    private String avatar;

    @Schema(description = "文章数量")
    private Integer articleCount;

    @Schema(description = "总浏览量")
    private Integer totalViews;

    @Schema(description = "总点赞数")
    private Integer totalLikes;

    @Schema(description = "个人简介")
    private String introduction;

    @Schema(description = "作者等级")
    private String authorLevel;

    @Override
    public String getDisplayName() {
        return username != null ? username : "未知作者";
    }

    @Override
    public String getStatusDescription() {
        return getAuthorLevelDescription();
    }

    /**
     * 获取作者等级描述
     */
    public String getAuthorLevelDescription() {
        if (authorLevel == null) {
            return calculateAuthorLevel();
        }
        return authorLevel;
    }

    /**
     * 计算作者等级
     */
    private String calculateAuthorLevel() {
        if (articleCount == null) return "新手作者";

        if (articleCount >= 100) {
            return "资深作者";
        } else if (articleCount >= 50) {
            return "高级作者";
        } else if (articleCount >= 20) {
            return "中级作者";
        } else if (articleCount >= 5) {
            return "初级作者";
        } else {
            return "新手作者";
        }
    }

    /**
     * 获取平均浏览量
     */
    public double getAverageViews() {
        if (articleCount == null || articleCount == 0 || totalViews == null) {
            return 0.0;
        }
        return (double) totalViews / articleCount;
    }

    /**
     * 检查是否为活跃作者
     */
    public boolean isActiveAuthor() {
        return articleCount != null && articleCount >= 5;
    }

    /**
     * 检查是否为热门作者
     */
    public boolean isPopularAuthor() {
        return totalViews != null && totalViews >= 10000;
    }

    /**
     * 获取显示头像
     */
    public String getDisplayAvatar() {
        return avatar != null && !avatar.trim().isEmpty() ? avatar : "/default-avatar.png";
    }

    /**
     * 获取简短介绍
     */
    public String getShortIntroduction() {
        if (introduction == null || introduction.trim().isEmpty()) {
            return "这位作者很神秘，什么都没有留下...";
        }
        return introduction.length() > 50 ? introduction.substring(0, 50) + "..." : introduction;
    }

    // 兼容性方法，保持向后兼容
    public String getId() {
        return userId;
    }

    public void setId(String id) {
        this.userId = id;
    }

    public String getName() {
        return username;
    }

    public void setName(String name) {
        this.username = name;
    }
}